﻿/** (UTF-8 with BOM)Winkawaks装甲勇士脚本,用于一键出招和一键秘籍,模拟器的暂停,静音切换
  By setycyas @2022-11-07
*/

/** 全局设定 
*/
#Warn
SendMode Input

/** 全局变量
*/
  
;常量,全体大写
global KEY_A := "w", KEY_B := "e", KEY_C := "s" ;设定ABC键位置

global D_DRILL := "D DRILL", F_CLAW := "F CLAW", C_SPARK := "C SPARK", L_BLADE := "L BLADE" ;手部武器枚举量
global FLAME := "FLAME", LASER := "LASER", BOMB := "BOMB", MISSILE := "MISSILE" ;肩部武器枚举量

global CHEAT_TABLE := {} ;秘籍指令表,用于每一关之前的武器选择秘籍
CHEAT_TABLE[D_DRILL] := ["up", KEY_B, KEY_C] ;D DRILL
CHEAT_TABLE[F_CLAW] := ["right", KEY_B, KEY_C] ; F CLAW
CHEAT_TABLE[C_SPARK] := ["down", KEY_B, KEY_C] ;C SPARK
CHEAT_TABLE[L_BLADE] := ["left", KEY_B, KEY_C] ;L BLADE
CHEAT_TABLE[FLAME] := ["left", "down", KEY_B, KEY_C] ;FLAME
CHEAT_TABLE[LASER] := ["right", "down", KEY_B, KEY_C] ;LASER
CHEAT_TABLE[BOMB] := ["left", "up", KEY_B, KEY_C] ;BOMB
CHEAT_TABLE[MISSILE] := ["right", "up", KEY_B, KEY_C] ;MISSILE

global FAV_WEAPONS := [D_DRILL, L_BLADE, FLAME, LASER] ;设定几个常用武器,用于一键设定秘籍

;变量
global delay1 := 100 ;技能延时1
global delay2 := 200 ;技能延时2
global cheatWeapon := D_DRILL ;当前秘籍武器

/** 操作函数 
*/

/* 技能1,按住A键后迅速按方向键
参数key为技能按键,用于等待按键放手时再松开A键
参数direction为方向键,应该是字符串up,down,left,right之一
*/ 
skill1(key, direction){
  send, {%KEY_A% down}
  sleep, %delay1%
  send, {%direction% down}
  sleep, %delay2%
  send, {%direction% up}
  ;等待key松开再发送A键松开
  while (GetKeyState(key)) {
    sleep, 20
  }
  send, {%KEY_A% up}
}

/* 秘籍1,每关开头按住方向键+BC选择武器
参数key为使用秘籍的技能,放开时发送按键松开指令
*/
cheat1(key){
  local i, v, k
  for i, v in CHEAT_TABLE[cheatWeapon] {
    k := CHEAT_TABLE[cheatWeapon][i]
    send, {%k% down}
    sleep, 20
  }
  ;等待key松开再发送A键松开
  while (GetKeyState(key)) {
    sleep, 50
  }
  for i, v in CHEAT_TABLE[cheatWeapon] {
    k := CHEAT_TABLE[cheatWeapon][i]
    send, {%k% up}
    sleep, 20
  }
}

/* 从FAV_WEAPONS中快速选择秘籍武器,如果当前武器是FAV_WEAPONS中的武器,则选择下一件,否则选择第一件FAV_WEAPON 
*/
selectFav(){
  local isSelected := 0 ;是否已经选择武器
  ;遍历,看看当前选择武器是否在FAV_WEAPONS中,如果在则选择下一件并标记isSelected
  For i, v in FAV_WEAPONS {
    if (cheatWeapon == v) {
      if (i == FAV_WEAPONS.Count()) {
        cheatWeapon := FAV_WEAPONS[1]
      } else {
        cheatWeapon := FAV_WEAPONS[i+1]
      }
      isSelected := 1
      break
    }
  }
  ;如果还没选择武器,则选择第一件FAV_WEAPONS
  if (!isSelected) {
    cheatWeapon := FAV_WEAPONS[1]
  }
  SB_SetText(cheatWeapon, 3)
}

/** 加入Gui并返回
*/
Gui, Add, Text, , 技能延时1:
Gui, Add, Edit, XP+100 Vdelay1, %delay1%
Gui, Add, Text, XP-100 YP+25, 技能延时2:
Gui, Add, Edit, XP+100 Vdelay2, %delay2%
Gui, Add, Text, XP-100 YP+25, 秘籍武器选择:
Gui, Add, ComboBox, XP+100 W80 VcheatWeapon Choose1, %D_DRILL%|%F_CLAW%|%C_SPARK%|%L_BLADE%|%FLAME%|%LASER%|%BOMB%|%MISSILE%
Gui, Add, Button, XP-100 YP+25 GButtonSubmit, 提交
Gui, Add, Button, XP+100 GButtonExit, 退出
Gui, Add, StatusBar
SB_SetParts(50, 50, 50)
SB_SetText(delay1, 1), SB_SetText(delay2, 2), SB_SetText(cheatWeapon, 3) ;状态栏显示当前数据
Gui, +AlwaysOnTop
Gui, Show, W230 H130, 装甲勇士
return

/** Gui响应 
*/
ButtonSubmit:
Gui, Submit, NoHide
SB_SetText(delay1, 1), SB_SetText(delay2, 2), SB_SetText(cheatWeapon, 3) ;状态栏显示当前数据
MsgBox, 数据提交成功!
return

ButtonExit:
GuiClose:
ExitApp
return

/** 快捷键设定 
*/
#IfWinActive, ahk_exe Winkawaks.exe
;q,r,2,3分别是左右上下技能
~q::
skill1("q", "left")
return

~r::
skill1("r", "right")
return

~2::
skill1("2", "up")
return

~3::
skill1("3", "down")
return

;x键使用秘籍
~x::
cheat1("x")
return

;切换暂停
~Numpad0::
send, {Enter Down}{Enter Up}
return

;切换静音
~Numpad1::
SoundSet, +1, , Mute
return

;切换秘籍武器,只在FAV_WEAPONS中切换
~RControl::
selectFav()
return

#IfWinActive